
// 修改头像
var avatarVip = ''//会员头像 
//加载模块  
layui.use(function () { //亦可加载特定模块：layui.use(['layer', 'laydate', function(){
    var layer = layui.layer //弹层
    var upload = layui.upload;
    let jingjiang_userinfo = JSON.parse(localStorage.getItem('jingjiang_userinfo'));
    $('#headImageId').on('click', function () {
        uploadImg()
    });
    //图片上传接口
    function uploadImg() {

        upload.render({
            elem: '#headImageId',
            headers: {
                token: jingjiang_userinfo.token
            },
            url: urls + '/api/common/upload', //改成你的图片上传接口
            accept: 'images', //指定允许上传的文件类型，可选值有：images（图片）、file（所有文件）、video（视频）、audio（音频）
            done: function (res) {
                //上传完毕回调
                console.log(res);
                avatarVip = res.data.fullurl;
                $(".avterHeader").attr("src", avatarVip);
                handleEditAvatar(res.data.url);
            },
            error: function () {
                //请求出错回调
                console.log('上传失败');
            }
        });
    }

    function handleEditAvatar(url) { 
        let datas = {
            url: '/api/user.user/editAvatar',
            http_type: 'POST',
            datas: {avatar:url}
        }
        wxx.HttpReqeust(datas, function (response) {
            if (response.code == 1) {
                layer.msg("头像更新成功")
            } else {
                layer.msg('温馨提示');
            }
        });
    }

});

